var jwt = require('jsonwebtoken')
let secret  = 'yikefuke'

// 生成token
exports.generateToken=(id,res)=>{
    let payload = {id:id,time:new Date()};
    let token   = jwt.sign(payload,secret,{expiresIn: 60*60*24*30})

    return token;
}

// 解码
exports.verifyToken = (e)=>{

    let payload
    jwt.verify(e,secret,(err,result)=>{
        if(err){
            payload = 0;
        }else{
            payload = 1;
        }
    });

    return payload;
}